#ifndef T_FUNCTION
#define T_FUNCTION

template <typename R,typename Arg> class invoker_base
{
public:
	virtual R operator()(Arg arg) = 0;
};

template <typename R,typename Arg> class function_ptr_invoker : public invoker_base<R,Arg>
{
public:
	function_ptr_invoker(R(*func)(Arg)):func_(func){};
	R operator()(Arg arg)
	{
		return (func_)(arg);
	};

private:
	typedef R (*Funcdef)(Arg);
	Funcdef	func_;
};

template <typename R,typename Arg,typename T> class member_ptr_invoker : public invoker_base<R,Arg>
{
public:
	member_ptr_invoker(R(T::*func)(Arg),T* t):func_(func),t_(t){};
	R operator()(Arg arg)
	{
		return (t_->*func_)(arg);
	};

private:
	typedef R (T::*Funcdef)(Arg);
	Funcdef	func_;
	T* t_;
};

template <typename R,typename Arg,typename T> class function_object_invoker : public invoker_base<R,Arg>
{
public:
	function_object_invoker(T t):t_(t){};
	R operator()(Arg arg)
	{
		return t_(arg);
	}

private:
	T t_;
};

template <typename R,typename Arg> class function1
{
public:
	function1(R(*func)(Arg)):invoker_(new function_ptr_invoker<R,Arg>(func)){};

	template<typename T> function1(R(T::*func)(Arg),T* t):invoker_(new member_ptr_invoker<R,Arg,T>(func,t)){};

	template<typename T> function1(T t):invoker_(new function_object_invoker<R,Arg,T>(t)){};

	~function1(void)
	{
		delete invoker_;
	}

	R operator()(Arg arg)
	{
		return (*invoker_)(arg);
	}

private:
	invoker_base<R,Arg>*	invoker_;
};

#endif